package com.yiwei.jmx.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.jmx.R;
import com.yiwei.jmx.activity.WebViewActivity;
import com.yiwei.jmx.api.model.DealIndexModel;
import com.yiwei.jmx.util.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class HomeOneAdapter extends ItemAdapter<DealIndexModel.DataBean.LifeBean, HomeOneAdapter.DefaultHolder> {


    //    private int[] img_res = new int[]{R.mipmap.img_home_type_car, R.mipmap.img_home_type_house, R.mipmap.img_home_type_car_fee, R.mipmap.img_home_type_learn_car, R.mipmap.img_home_type_borrow_house, R.mipmap.img_home_type_more};
    private Context context;

    //    private String[][] text_string={
//            {"车贷","最高可贷20万"},
//            {"房抵贷","最快次日放款"},
//            {"车险分期","一站式车险"},
//            {"学车分期","轻松学车 快乐拿证"},
//            {"租房分期","利息手续费全免"},
//            {"更多精彩","敬请期待"}
//    };
    public HomeOneAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_home_one, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
//        GlideUtil.loadImg(context, img_res[position], holder.layoutTotal);
//        holder.txtName.setText(text_string[position][0]);
//        holder.txtDesc.setText(text_string[position][1]);
//        if(position==getItemCount()-1){
//            holder.txtName.setTextColor(0xffA6A6A6);
//            holder.txtDesc.setTextColor(0xffA6A6A6);
//        }else {
//            holder.txtName.setTextColor(0xffFFFFFF);
//            holder.txtDesc.setTextColor(0xffFFFFFF);
//        }
        DealIndexModel.DataBean.LifeBean item = getItem(position);
//        GlideUtil.loadImg(context, item.img, holder.layoutTotal);
        Glide.with(context).load(item.img).into(holder.imgIcon);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("title", "信用生活");
                intent.putExtra("url", item.link);
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
